package com.android.jay.wzp_voice.view.home.adapter;

import com.android.jay.wzp_voice.discory.DiscoryFragment;
import com.android.jay.wzp_voice.friend.FriendFragment;
import com.android.jay.wzp_voice.mine.MineFragment;
import com.android.jay.wzp_voice.model.CHANNEL;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

/**
 * Created by wzp on 2019/11/4 0004.
 * <p>
 * 描述  ：首页 viewpageradapter
 */
public class HomePageAdapter extends FragmentPagerAdapter {

    private CHANNEL[] mLists;

    public HomePageAdapter(FragmentManager fm, CHANNEL[] datas) {
        super(fm);
        mLists = datas;
    }

    //初始化对应的fragment 避免一次性创建所有的framgent
    @Override
    public Fragment getItem(int i) {
        int type = mLists[i].getValue();
        switch (type) {
            case CHANNEL.MINE_ID:
                return MineFragment.newInstance();
            case CHANNEL.DISCORY_ID:
                return DiscoryFragment.newInstance();
            case CHANNEL.FRIEND_ID:
                return FriendFragment.newInstance();
        }
        return null;
    }

    @Override
    public int getCount() {
        return mLists == null ? 0 : mLists.length;
    }
}
